package cn.yunhe.controller;

import cn.yunhe.entity.User;
import cn.yunhe.service.IUserService;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/before/LadingUserServlet")
public class LadingUserServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                               String userName = request.getParameter("username");
                               String userPass = request.getParameter("password");
                               User user = new User();
                               user.setUserName(userName);
                               user.setUserPass(userPass);
                               IUserService iUserService = new IUserService();
                               User us = iUserService.userLadmin(user);
                              PrintWriter out = response.getWriter();
                               if (us!=null){
                                    request.getSession().setAttribute("user",us);
                                    response.sendRedirect("/before/index.html");
                               }else {
                                   response.setContentType("text/html;charset=UTF-8");
                                   out.print("<script>alert('该账号不存或者密码错误');location.href='login.html'</script>");
                               }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
